package com.hmj.hmjaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;


@Configuration
public class LoveAppVectorStoreConfig {

    @Resource
    private MyTokenTextSplitter textSplitter;
    @Resource
    private LoveAppDocumentReader reader;
    @Resource
    private MyKeywordEnricher enricher;

    @Bean
    SimpleVectorStore LoveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore vectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel)
                .build();
        //加载文档
        List<Document> documents = reader.loadMarkdowns();
//        //使用自定义切分策略，可修改
//        List<Document> documents1 = textSplitter.splitDocuments(documents);
//        //使用AI自动获取文档元数据功能
//        List<Document> documents2 = enricher.enrichDocuments(documents1);
        vectorStore.add(documents);
        return vectorStore;
    }
}
